<template>
	<view>
		<button @click="onSetTimeCall()">单次定时器settime</button>
		<button @click="onSetTimeCallxx(userName,password)">单次定时器2settime</button>
		<button @click="onSetTimeout()" type="warn">取消定时器settime</button>
		<button @click="onInterai()">周期定时器settime</button>
		<button @click="onSetTimeout1()" type="warn">取消周期定时器</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userName:'ycy',
				password:'111',
				timeoutId:null,
				count:0,
				interalId:null
			}
		},
		methods: {
			onSetTimeCall(){
				console.log("onSetTimeCall-->");
				//setTimeout(callback,ms,any[]
				this.timeoutId = setTimeout(()=>{
					//延时2000ms后执行的代码
					// ()=>{  }
					console.log("延时2s打印");
				},5000)
			},
			onSetTimeCallxx(name,pwd){
				console.log("onSetTimeCallxx-->name"+name+",pwd:"+pwd);
				//console.log("onSetTimeCallxx-->name"+this.userName+",pwd:"+this.password);
				setTimeout((x,y)=>{
				console.log("传参数"+name+",pwd:"+pwd);
				},2000,name,pwd)
			},
			onSetTimeout(){
				console.log("取消"+ this.timeoutId);
				clearTimeout(this.timeoutId);
			},
			onInterai(){
				this.interalId = setInterval(()=>{
					this.count++;
					console.log("周期打印",this.count);
				},1000)
			},
			onSetTimeout1(){
				console.log("取消周期"+ this.interalId);
				clearTimeout(this.interalId);
			},
		}
	}
</script>

<style>

</style>
